﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration.Provider;

namespace XWord.Data.Provider
{
    public class GenericProviderCollection<T> : ProviderCollection where T : ProviderBase
    {
        /// <summary>
        /// Returns a provider by the specified section key.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public new T this[string name]
        {
            get { return (T)base[name]; }
        }

        /// <summary>
        /// Adds a new provider to the collection.
        /// </summary>
        /// <param name="provider"></param>
        public override void Add(ProviderBase provider)
        {
            if (provider == null)
                throw new ArgumentNullException("provider");

            if (!(provider is T))
                throw new ArgumentException
                    ("Invalid provider type", "provider");

            base.Add(provider);
        }
    }
}
